package cn.com.haopy.yue.ai.db.service.hos.impl;

import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskPapersIndex;
import cn.com.haopy.yue.ai.db.mapper.arisk.AIRiskPapersIndexMapper;
import cn.com.haopy.yue.ai.db.service.BaseServiceImpl;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskPapersIndexService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description: TODO
 * @Author DuTao
 * @Date 2025/4/1 11:36
 */
@Service
public class AIRiskPapersIndexServiceImpl extends BaseServiceImpl<AIRiskPapersIndexMapper, AIRiskPapersIndex> implements AIRiskPapersIndexService {
    @Override
    public List<AIRiskPapersIndex> getByPapersId(Integer id, Integer illnessId) {
        LambdaQueryWrapper<AIRiskPapersIndex> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersIndex::getPaperId, id);
        queryWrapper.eq(AIRiskPapersIndex::getIllnessId, illnessId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public AIRiskPapersIndex getByPapersIndexByPaperId(Integer paperId, Integer illnessId, Integer indexId) {
        LambdaQueryWrapper<AIRiskPapersIndex> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersIndex::getPaperId, paperId);
        queryWrapper.eq(AIRiskPapersIndex::getIndexId, indexId);
        queryWrapper.and(wrapper -> {
            wrapper.eq(AIRiskPapersIndex::getIllnessId, illnessId).or().isNull(AIRiskPapersIndex::getIllnessId);
        });
        return baseMapper.selectOne(queryWrapper);
    }


    @Override
    public List<Map<String, String>> getHasValueByPapersId(Integer paperId) {
        return baseMapper.getHasValueByPapersId(paperId);
    }

    @Override
    public List<AIRiskPapersIndex> getNotEmptyByPapersId(Integer paperId) {
        LambdaQueryWrapper<AIRiskPapersIndex> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersIndex::getPaperId, paperId);
        queryWrapper.isNotNull(AIRiskPapersIndex::getIndexValue);
        queryWrapper.ne(AIRiskPapersIndex::getIndexValue, "");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<AIRiskPapersIndex> getIndexByPapersIdAll(Integer paperId) {
        LambdaQueryWrapper<AIRiskPapersIndex> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersIndex::getPaperId, paperId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<AIRiskPapersIndex> getIndexByPapersIdNotAge(Integer paperId) {
        LambdaQueryWrapper<AIRiskPapersIndex> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersIndex::getPaperId, paperId);
        queryWrapper.ne(AIRiskPapersIndex::getIndexName, "年龄");
        return baseMapper.selectList(queryWrapper);
    }
}
